package logic

import (
	"context"
	"user-auth/models/mysql"

	"user-auth/userrpc/internal/svc"
	"user-auth/userrpc/userrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type GoodsAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGoodsAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GoodsAddLogic {
	return &GoodsAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *GoodsAddLogic) GoodsAdd(in *userrpc.GoodsAddRequest) (*userrpc.GoodsAddResponse, error) {
	// todo: add your logic here and delete this line

	goods := &mysql.Goods{
		GoodsName:  in.GoodsName,
		GoodsPrice: in.GoodsPrice,
		GoodsStock: in.GoodsStock,
		UserId:     in.UserId,
	}

	if err := goods.GoodsAdd(mysql.DB); err != nil {
		return nil, err
	}

	return &userrpc.GoodsAddResponse{
		GoodsId: int64(goods.ID),
	}, nil
}
